<?php namespace Home\Controller; 

//use Hdphp\Controller\Controller;

//购物车提交控制器   
class ConfirmController extends CommonController{

	//构造函数
	public function __init()
	{
		parent::__init();
	}
	
    //动作
    public function index(){
		if(!IS_POST){
			View::error('请提交购车数据',U('Cart/index'));
		}	   
			  
		$glid=Q('post.glid');
//		抓取选中的商品
		$_SESSION['cartglid']=$glid;
//		p($_SESSION);die;
		$data=$this->getCartGoods($glid);
//		p($data);
		View::with('data',$data);		
		
		$uid=$_SESSION['id'];
		$addressModel=new \Common\Model\User_address;
		$addressData=$addressModel->where('user_uid',$uid)->where('common','yes')->find();
//		var_dump($addressData);	   
		View::with('addressData',$addressData);	
	   View::make();
    }
	
	public function getCartGoods($glid){
		
		$data=Cart::getGoods();
//		var_dump($data);die;
		$comData=array();
		$totalData=array();
		foreach($data as $k=>$v){
			if(in_array($k,$glid)){
				$comData['goods'][]=$v;				
				$totalData[]=$v['total'];
			}
		}

		$comData['total_all']=array_sum($totalData);
//		array_sum 求和
//		var_dump($comData);die;
		return $comData;
		
	}
	
	

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
